package com.airconditioner.sales.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.airconditioner.sales.R;


public class CategroyGridAdapter extends RecyclerView.Adapter<CategroyGridAdapter.ItemViewHolder> {
    private LayoutInflater inflater;
    private MyItemClickListener itemClickListener;
    Context mContext;


    public CategroyGridAdapter(Context context) {
        mContext = context;
        inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public CategroyGridAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.activity_little_category_list_row, null);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClickListener.onItemClick(v, (Integer) v.getTag());
            }
        });
        ItemViewHolder viewHolder = new ItemViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        ItemViewHolder viewHolder = holder;
        viewHolder.itemView.setTag(position);

    }

    @Override
    public int getItemCount() {
        return 5;
    }

    public static class ItemViewHolder extends RecyclerView.ViewHolder {
        public TextView nameView;

        public ItemViewHolder(View itemView) {
            super(itemView);
            nameView = (TextView) itemView.findViewById(R.id.little_category_tv_name);
        }
    }

    public interface MyItemClickListener {
        void onItemClick(View view, int postion);
    }

    public void setOnItemClickListener(MyItemClickListener listener) {
        this.itemClickListener = listener;
    }
}
